package xzl.edu.cn.set.demo;

import java.util.Map.Entry;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import xzl.edu.cn.set.Book;

public class MapMathed {
	Logger logger = LogManager.getLogger(MapMathed.class);
	Student stu[] = new Student[10];
	Map<String, Student> map = new HashMap<String, Student>();

	/**
	 * 添加学生信息到Map
	 */
	public void setstudent() {
		for (int i = 0; i < 10; i++)
			stu[i] = new Student("2016080302" + (i + 1), "网络162班", "网络" + i);
		for (int i = 0; i < 10; i++)
			map.put(stu[i].name, stu[i]);
	}

	/**
	 * 键值方式遍历
	 */
	public void showkey() {
		setstudent();
		Set<String> keyset = map.keySet();
		for (String stuId : keyset) {
			Student student = map.get(stuId);
			logger.info(student.toString());
		}
	}

	/**
	 * 迭代器方式遍历
	 */
	public void showItera() {
		setstudent();
		Set<Entry<String, Student>> set = map.entrySet();
		Iterator<Entry<String, Student>> it = set.iterator();
		while (it.hasNext()) {
			Entry<String, Student> entry = it.next();
			Student s = entry.getValue();
			logger.info(s.toString());
		}
	}
    
}
